package com.cjl.generic;

class Node<T> {

    public T data;

    public Node(T data) { this.data = data; }

    public void setData(T data) {
        System.out.println("Node.setData");
        this.data = data;
    }

    public T getData() {
        return data;
    }
}

public class MyNode extends Node<Integer> {
    public MyNode(Integer data) { super(data); }

    @Override
    public void setData(Integer data) {
        System.out.println("MyNode.setData");
        super.setData(data);
    }

    @Override
    public Integer getData() {
        System.out.println("MyNode.getData");
        return super.getData();
    }

    public static void main(String[] args) {
        MyNode mn = new MyNode(5);
        Node n = mn;            // 多态行为，且赋值为了原生类型
        n.setData("Hello");    // 会引发抛出ClassCastException
        Integer x = mn.data;
    }
}

